import 'package:json_annotation/json_annotation.dart';
part 'recipe_category_api.g.dart';

@JsonSerializable()
class ResponseRecipeCategoryApi {
  final int total;
  final List<RecipeCategory> rows;

  ResponseRecipeCategoryApi(this.total, this.rows);

  factory ResponseRecipeCategoryApi.fromJson(Map<String, dynamic> json) =>
      _$ResponseRecipeCategoryApiFromJson(json);
}

@JsonSerializable() // 必须添加注解
class RecipeCategory {
  final String id;
  final String? imageUrl;
  final String? name;
  final int nodeType;
  final int sort;
  final int? belongRecipeCount;
  final List<RecipeCategory>? childrenList;

  RecipeCategory({
    this.imageUrl,
    this.name,
    required this.nodeType,
    required this.id,
    required this.sort,
    required this.belongRecipeCount,
    required this.childrenList,
  });

  // 必须包含这两个方法
  factory RecipeCategory.fromJson(Map<String, dynamic> json) =>
      _$RecipeCategoryFromJson(json);

  Map<String, dynamic> toJson() => _$RecipeCategoryToJson(this);

  factory RecipeCategory.initial() => RecipeCategory(
    imageUrl: null,
    name: null,
    nodeType: 0,
    id: '',
    sort: 0,
    belongRecipeCount: 0,
    childrenList: <RecipeCategory>[],
  );
}
